<template>
  <div class="home">
    <van-nav-bar>
      <template #left>
        <van-image
          round
          width="40px"
          height="40px"
          src="https://img01.yzcdn.cn/vant/cat.jpeg"
        />
      </template>
      <template #right>
        <van-search
          class="input"
          input-align="center"
          shape="round"
          background="#f2f2f2"
          left-icon="search"
        />
      </template>
    </van-nav-bar>
    <!-- 轮播 -->
    <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
      <van-swipe-item v-for="item in lunbolist" :key="item.id">
        <img :src="item.src" />
      </van-swipe-item>
    </van-swipe>
    <!-- 中间分类 -->
    <div class="fenglei">
      <van-grid :column-num="4">
        <van-grid-item icon="shop" text="小米之家" />
        <van-grid-item icon="exchange" text="以旧换新" />
        <van-grid-item icon="tv-o" text="电视热卖" color="#ffbe35" />
        <van-grid-item icon="smile-comment" text="小米助手" color="#ffbe35" />
      </van-grid>
    </div>
    <div class="line"></div>
    <!-- 商品列表 -->
    <div class="goodslist">
      <van-grid direction="horizontal" :column-num="2">
        <div
          icon="photo-o"
          v-for="lel in splist"
          :key="lel.id"
          @click="gotoMenu(lel.id)"
        >
          <img :src="lel.img" />
          <div class="info">
            <span class="span1">{{ lel.name }}</span
            ><br />
            <span class="span2">{{ lel.content }}</span
            ><br />
            <span class="span3">￥{{ lel.price }}</span>
          </div>
        </div>
      </van-grid>
    </div>
  </div>
</template>
<script>
import { shangpinList, getLunbo } from '../../api/home'
export default {
  data: () => ({
    props: ['id'],
    lunbolist: [],
    splist: []
  }),
  created() {
    this.getLunbo()
    this.shangpinList()
  },
  methods: {
    async getLunbo() {
      const res = await getLunbo()
      this.lunbolist = res.data.message
    },
    async shangpinList() {
      const res = await shangpinList()
      this.splist = res.data.message
    },
    gotoMenu(id) {
      // console.log(this.id)
      this.$router.push('home/Xhome/' + id)
    }
  }
}
</script>
<style lang="less">
.home {
  .van-nav-bar__left {
    padding: 0 20px;
  }
  .van-nav-bar__content {
    height: 65px;
    background: #f2f2f2;
  }
  .van-search {
    padding: 0 12px;
    .van-search__content {
      width: 211px;
      height: 30px;
      border: 1px solid #e5e5e5;
      background: #fff;
      .van-cell {
        padding: 0 8px 0;
        line-height: 32px;
        .van-field__left-icon {
          margin-left: -8px;
        }
        .van-icon {
          color: #ddd;
          font-size: 22px;
        }
        .van-cell__value {
          .van-field__control--center {
            text-align: left;
          }
        }
      }
    }
  }
  .my-swipe .van-swipe-item {
    line-height: 150px;
    height: 187.5px;
    img {
      width: 100%;
      height: 100%;
    }
  }
  .fenglei {
    width: 100%;
    height: 72px;
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    .van-grid {
      display: flex;
    }
    .van-grid-item {
      height: 100%;
      background-color: rebeccapurple;
    }
  }
  .line {
    background-color: #f5f5f5;
    height: 20px;
  }
  .goodslist {
    .van-grid {
      justify-content: space-between;
      img {
        width: 185px;
        height: 185px;
      }
      div {
        margin: 0;
        width: 185px;
        height: 266px;
        .info {
          padding: 10px;
          width: 185px;
          height: 60px;
          box-sizing: border-box;
          .span1 {
            font-size: 18px;
            color: rgba(0, 0, 0, 0.87);
          }
          .span2 {
            margin-top: 0.06rem;
            font-size: 12px;
            line-height: 0.3rem;
            color: rgba(0, 0, 0, 0.54);
          }
          .span3 {
            font-size: 16px;
            color: #ea625b;
            height: 1.5em;
            line-height: 1.5em;
          }
        }
      }
    }
  }
}
</style>
